package com.xiaoyu.awakening.common.core.openapi;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author wangxiaoyu
 * @date 2024/5/30 14:12
 * @since v1.0
 */
@Configuration
@EnableConfigurationProperties(OpenApiDocProperties.class)
@Slf4j
public class OpenApiDocAutoConfig {
    @Bean
    public OpenAPI config(OpenApiDocProperties openApiDocProperties) {
        log.info("------------- init openAPI start-------------------");
        Contact contact = new Contact();
        contact.setName(openApiDocProperties.getContactName());
        contact.setUrl(openApiDocProperties.getContactUrl());
        contact.setEmail(openApiDocProperties.getContactEmail());

        License license = new License();
        license.setName(openApiDocProperties.getLicense());
        license.setUrl(openApiDocProperties.getLicenseUrl());
        log.info("------------- init openAPI end  -------------------");
        return new OpenAPI().info(new Info()
                .title(openApiDocProperties.getTitle())
                .description(openApiDocProperties.getDescription())
                .license(license)
                .contact(contact)
        );
    }
}
